package com.yonyou.pmclouds.projectstatus.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.yonyou.pmclouds.ApplicationConsts;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.runtime.RuntimeEnvironment;
import com.yonyou.pmclouds.projectstatus.entity.ProjectStatusOutViewVO;
import com.yonyou.pmclouds.projectstatus.rmiitf.ProjectStatusMaintain;
import com.yonyou.pmclouds.projectstatus.rmiitf.ProjectStatusOutterMaintain;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping(value = "/outter/projectstatus")
public class ProjectStatusOutterController {

    @Reference(version = ApplicationConsts.APPLICATION_VERSION)
    private ProjectStatusOutterMaintain maintain;

    @ResponseBody
    @RequestMapping("/updateFromOutter")
    public ProjectStatusOutViewVO updateFromOutter(@RequestBody ProjectStatusOutViewVO projectStatusOutViewVO,HttpServletRequest request) throws BusinessException {

        setTenantInfo(request);

        return maintain.updateFromOutter(projectStatusOutViewVO);
    }


    private void setTenantInfo(HttpServletRequest request) throws BusinessException{
        String tenantId = request.getHeader("accountId");
        if(StringUtils.isEmpty(tenantId))
            throw new BusinessException("未找到对应租户信息");
        RuntimeEnvironment.setTenantId(tenantId);
    }


}
